<!--
@license
Copyright 2016 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-item/paper-item.html">
<link rel="import" href="../paper-listbox/paper-listbox.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../paper-checkbox/paper-checkbox.html">
<link rel="import" href="../paper-tooltip/paper-tooltip.html">
<link rel="import" href="vz-projector-legend.html">

<dom-module id='vz-projector-data-panel'>
<template>
<style>
:host {
}

input[type=file] {
  display: none;
}

.file-name {
  margin-right: 10px;
}

.dirs {
  display: flex;
  flex-direction: column;
  margin: 15px 0;
  line-height: 20px;
}

.dir {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

paper-item {
  --paper-item-disabled: {
    border-bottom: 1px solid black;
    justify-content: center;
    font-size: 12px;
    line-height: normal;
    min-height: 0px;
  };
}

.item-details {
  margin-left: 5px;
  color: gray;
  font-size: 12px;
}

paper-button {
  border: 1px solid #ccc;
}

#save-container {
  text-align: center;
}

.state-row {
  display: table-row;
}

.state-radio {
  display: table-cell;
  vertical-align: middle;
  padding-top: 16px;
}

.state-label {
  display: table-cell;
  vertical-align: middle;
  top: 14px;
}

.state-clear {
  display: table-cell;
  vertical-align: middle;
  top: 14px;
}

.help-icon {
  width: 15px;
  height: 15px;
  margin: 0;
  padding: 0;
}

paper-tooltip {
  max-width: 200px;
  --paper-tooltip: {
    font-size: 12px;
  };
}

paper-checkbox {
  --paper-checkbox-checked-color: #880E4F;
}
</style>

<div>
  <!-- Upload buttons -->
  <div style="display: flex; justify-content: space-between;">
    <!-- Upload data -->
    <div>
      <button id="upload" title="Upload a TSV file" class="ink-button">Upload data</button>
      <input type="file" id="file" name="file"/>
    </div>

    <!-- Upload metadata -->
    <div>
      <button id="upload-metadata" title="Upload a TSV metadata file" class="ink-button">Upload Metadata</button>
      <input type="file" id="file-metadata" name="file-metadata"/>
    </div>
  </div>

  <div class="dirs">
    <div class="dir">Checkpoint: <span id="checkpoint-file"></span></div>
    <div class="dir">Metadata: <span id="metadata-file"></span></div>
  </div>

  <paper-checkbox id="normalize-data-checkbox" checked="{{normalizeData}}">
    Normalize data
    <paper-icon-button icon="help" class="help-icon"></paper-icon-button>
    <paper-tooltip position="bottom" animation-delay="0" fit-to-visible-bounds>
      The data is normalized by shifting each point by the centroid and making
      it unit norm.
    </paper-tooltip>
  </paper-checkbox>

  <!-- List of runs -->
  <template is="dom-if" if="[[_hasChoices(runNames)]]">
    <paper-dropdown-menu no-animations label="[[_getNumRunsLabel(runNames)]] found">
      <paper-listbox attr-for-selected="value" class="dropdown-content" selected="{{selectedRun}}">
        <template is="dom-repeat" items="[[runNames]]">
          <paper-item style="justify-content: space-between;" value="[[item]]" label="[[item]]">
            [[item]]
          </paper-item>
        </template>
      </paper-listbox>
    </paper-dropdown-menu>
  </template>

  <template is="dom-if" if="[[tensorNames]]">
    <!-- List of tensors in checkpoint -->
    <paper-dropdown-menu no-animations label="[[_getNumTensorsLabel(tensorNames)]] found">
      <paper-listbox attr-for-selected="value" class="dropdown-content" selected="{{selectedTensor}}">
        <template is="dom-repeat" items="[[tensorNames]]">
          <paper-item style="justify-content: space-between;" value="[[item.name]]" label="[[item.name]]">
            [[item.name]]
            <span class="item-details">
              [[item.shape.0]]x[[item.shape.1]]
            </span>
          </paper-item>
        </template>
      </paper-listbox>
    </paper-dropdown-menu>
  </template>
</div>

<!-- Label by -->
<template is="dom-if" if="[[_hasChoices(labelOptions)]]">
  <paper-dropdown-menu style="width: 100%" no-animations label="Label by">
    <paper-listbox attr-for-selected="value" class="dropdown-content" selected="{{labelOption}}">
      <template is="dom-repeat" items="[[labelOptions]]">
        <paper-item style="justify-content: space-between;" value="[[item]]" label="[[item]]">
          [[item]]
        </paper-item>
      </template>
    </paper-listbox>
  </paper-dropdown-menu>
</template>

<!-- Color by -->
<template is="dom-if" if="[[_hasChoices(colorOptions)]]">
  <paper-dropdown-menu id="colorby" style="width: 100%" no-animations label="Color by">
    <paper-listbox attr-for-selected="value" class="dropdown-content" selected="{{colorOption}}">
      <template is="dom-repeat" items="[[colorOptions]]">
        <paper-item style="justify-content: space-between;" class$="[[getSeparatorClass(item.isSeparator)]]" value="[[item]]" label="[[item.name]]" disabled="[[item.isSeparator]]">
          [[item.name]]
          <span class="item-details">[[item.desc]]</span>
        </paper-item>
      </template>
    </paper-listbox>
  </paper-dropdown-menu>
  <vz-projector-legend render-info="[[colorLegendRenderInfo]]"></vz-projector-legend>
</template>

<!-- Saving state section -->
<div id="state-section" style="display: none">
  <div style="display: flex; justify-content: space-between;">
    <button id="state-download" title="Save all states" class="ink-button">Save all states</button>
    <button id="state-upload" title="Load states file" class="ink-button">Load states file</button>
  </div>
  <input type="file" id="state-file" name="state-file"/>

  <template is="dom-repeat" items="{{savedStates}}">
    <div class="state-row">
      <div class="state-radio">
        <template is="dom-if" if="{{item.isSelected}}">
          <paper-icon-button icon="radio-button-checked"></paper-icon-button>
        </template>
        <template is="dom-if" if="{{!item.isSelected}}">
          <paper-icon-button
              icon="radio-button-unchecked"
              data-index$="{{index}}"
              on-tap="_radioButtonHandler"></paper-icon-button>
        </template>
      </div>
      <div class="state-label">
        <paper-input value="[[item.label]]" on-change="_labelChange" data-index$="[[index]]" autoresizing></paper-input>
      </div>
      <div class="state-clear">
        <paper-icon-button
            icon="clear"
            data-index$="{{index}}"
            on-tap="_clearButtonHandler"></paper-icon-button>
      </div>
    </div>
  </template>
  <button id="state-add" title="Add current view" class="ink-button">Add current view</button>
</template>

<!-- Closing global template -->
</template>
</dom-module>
